<?php
/*
+-----------------------------------------------------------------------------+
| $Id: *.php,v 1.* 2005/07/01 06:15:08 Bleakwind Exp $
| SnowStats
|         --- A Web Statistics Analysis for multiuser
| Copyright (c) 2003-2005 Weaverdream.com By Bleakwind
| http://www.weaverdream.com
+-----------------------------------------------------------------------------+
*/

include_once 'include/include.php';
check_adminlogin();
include_once 'include/header.php';
?>

<table width="760" border="0" cellpadding="0" cellspacing="0" bgcolor="#5E94DD" align="center">
  <tr bgcolor="#5E94DD">
    <td width="200" align="center" valign="top" class="left_bg">
      <?include_once 'include/menu.php';?>
	</td>
	<td width="560" bgcolor="#FFFFFF" valign="top">

<?php
if(empty($_GET['act'])){

$website = str_decode(CONFIG_WEBSITE);
$weburl  = str_decode(CONFIG_WEBURL);

if(CONFIG_IFUSER     == "y") {$ifuser_y     = " checked";}else{$ifuser_n     = " checked";}
if(CONFIG_IFUSERLIST == "y") {$ifuserlist_y = " checked";}else{$ifuserlist_n = " checked";}
if(CONFIG_IFVIEW     == "y") {$ifview_y     = " checked";}else{$ifview_n     = " checked";}
?>

<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#EBE9ED"><tr><td><img src="images/arrowright.gif" border=0 align="absmiddle"> <a href="index.php" target="_self"><font style="color:#000000;"><?php echo CONFIG_WEBSITE;?></font></a> &raquo; <?php echo $LANGUAGE['admin_amend_placedir'];?> &raquo; <?php echo $LANGUAGE['admin_amend_place'];?></td></tr></table>
<br>

<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
<form action="admin_amend.php?act=save" method="post" name="form">
<tr><td>

<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF">
<tr bgcolor="#5E94DD"><td colspan="3" align="center" class="right_title"><?php echo $LANGUAGE['admin_amend_general'];?></td></tr>

<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_adminuser'];?></td><td width="40%" class="right_content"><input type="text" name="adminuser" size="26" maxlength="60" class="input" value="<?php echo CONFIG_ADMINUSERNAME;?>"></td><td width="40%" class="right_content"></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_current_password'];?></td><td width="40%" class="right_content"><input type="password" name="adminpass1" size="26" maxlength="60" class="input"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_current_password_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_new_password'];?></td><td width="40%" class="right_content"><input type="password" name="adminpass2" size="26" maxlength="60" class="input"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_new_password_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_confirm_password'];?></td><td width="40%" class="right_content"><input type="password" name="adminpass3" size="26" maxlength="60" class="input"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_confirm_password_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_email'];?></td><td width="40%" class="right_content"><input type="text" name="email" size="26" maxlength="160" class="input" value="<?php echo CONFIG_EMAIL;?>"></td><td width="40%" class="right_content"></td></tr>

<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_website'];?></td><td width="40%" class="right_content"><input type="text" name="website" size="26" maxlength="160" class="input" value="<?php echo $website;?>"></td><td width="40%" class="right_content"></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_weburl'];?></td><td width="40%" class="right_content"><input type="text" name="weburl" size="26" maxlength="160" class="input" value="<?php echo $weburl;?>"></td><td width="40%" class="right_content"></td></tr>

<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_url'];?></td><td width="40%" class="right_content"><input type="text" name="url" size="26" maxlength="160" class="input" value="<?php echo CONFIG_URL;?>"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_url_explain'];?></td></tr>
<tr>
  <td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_language'];?></td>
  <td width="40%" class="right_content">
<?php
$file_list     = return_dir("language/");
$total_record = count($file_list);
echo "<select name='language' class='select' size=1>";
$selected = (CONFIG_LANGUAGE == "chinese_simplified") ? " selected" : "";
echo "<option value='chinese_simplified' ".$selected.">chinese_simplified</option>";
for($i=0;$i<$total_record;$i++){
if(trim($file_list[$i]) != "chinese_simplified"){
    $selected = (CONFIG_LANGUAGE == trim($file_list[$i])) ? " selected" : "";
    echo "<option value='".$file_list[$i]."' ".$selected.">".$file_list[$i]."</option>";
}
}
echo "</select>";
?>
  </td>
  <td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_language_explain'];?></td>
</tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_webintro_long'];?></td><td width="40%" class="right_content"><input type="text" name="webintro_long" size="26" maxlength="10" class="input" value="<?php echo CONFIG_WEBINTRO_LONG;?>"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_webintro_long_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_last_visitor'];?></td><td width="40%" class="right_content"><input type="text" name="last_visitor" size="26" maxlength="10" class="input" value="<?php echo CONFIG_LAST_VISITOR;?>"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_last_visitor_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_ifcount_long'];?></td><td width="40%" class="right_content"><input type="text" name="ifcount_long" size="26" maxlength="60" value="<?php echo CONFIG_IFCOUNT_LONG;?>" class="input"> sec.</td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_ifcount_long_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_online_long'];?></td><td width="40%" class="right_content"><input type="text" name="online_long" size="26" maxlength="60" value="<?php echo CONFIG_ONLINE_LONG;?>" class="input"> sec.</td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_online_long_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_del_number'];?></td><td width="40%" class="right_content"><input type="text" name="del_number" size="26" maxlength="10" class="input" value="<?php echo CONFIG_DEL_NUMBER;?>"></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_del_number_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_del_long'];?></td><td width="40%" class="right_content"><input type="text" name="del_long" size="26" maxlength="10" class="input" value="<?php echo CONFIG_DEL_LONG;?>"> sec.</td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_del_long_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_ifuser'];?></td><td width="40%" class="right_content"><input type="radio" name="ifuser" value="y" <?php echo $ifuser_y;?> class="radio_y"> <?php echo $LANGUAGE['admin_amend_yes'];?> <input type="radio" name="ifuser" value="n" <?php echo $ifuser_n;?> class="radio_n"> <?php echo $LANGUAGE['admin_amend_no'];?></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_ifuser_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_ifuserlist'];?></td><td width="40%" class="right_content"><input type="radio" name="ifuserlist" value="y" <?php echo $ifuserlist_y;?> class="radio_y"> <?php echo $LANGUAGE['admin_amend_yes'];?> <input type="radio" name="ifuserlist" value="n" <?php echo $ifuserlist_n;?> class="radio_n"> <?php echo $LANGUAGE['admin_amend_no'];?></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_ifuserlist_explain'];?></td></tr>
<tr><td width="20%" class="right_subject"><?php echo $LANGUAGE['admin_amend_ifview'];?></td><td width="40%" class="right_content"><input type="radio" name="ifview" value="y" <?php echo $ifview_y;?> class="radio_y"> <?php echo $LANGUAGE['admin_amend_yes'];?> <input type="radio" name="ifview" value="n" <?php echo $ifview_n;?> class="radio_n"> <?php echo $LANGUAGE['admin_amend_no'];?></td><td width="40%" class="right_content"><?php echo $LANGUAGE['admin_amend_ifview_explain'];?></td></tr>

<tr><td colspan="3" align="center"><input type="submit" value="<?php echo $LANGUAGE['admin_amend_submit'];?>" name="submit" class="submit"><input type="reset" value="<?php echo $LANGUAGE['admin_amend_reset'];?>" name="reset" class="submit"></td></tr></table>

</td></tr></form></table>

<?php
}elseif($_GET['act'] == "save") {

if($_POST['adminuser'] == "" || $_POST['email'] == "" || $_POST['website'] == "" || $_POST['weburl'] == "" || $_POST['weburl'] == "http://" || $_POST['url'] == "" || $_POST['language'] == "" || $_POST['webintro_long'] == "" || $_POST['last_visitor'] == ""){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_empty'])));
   exit;
}
if($_POST['adminpass2'] != $_POST['adminpass3']){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_pass_differ'])));
   exit;
}
if(!preg_match("/^[0-9a-z_]{3,60}$/i",$_POST['adminuser'])){
    header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_adminuser_error'])));
    exit;
}
if(!preg_match("/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$/i",$_POST['email'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_email_error'])));
   exit;
}
if(!preg_match("/^[0-9]{1,60}$/",$_POST['webintro_long'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_webintro_long_error'])));
   exit;
}
if(!preg_match("/^[0-9]{1,60}$/",$_POST['last_visitor'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_last_visitor_error'])));
   exit;
}
if(!preg_match("/^[0-9]{1,60}$/",$_POST['ifcount_long'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_ifcount_long_error'])));
   exit;
}
if(!preg_match("/^[0-9]{1,60}$/",$_POST['online_long'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_online_long_error'])));
   exit;
}
if(!preg_match("/^[0-9]{1,60}$/",$_POST['del_number'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_del_number_error'])));
   exit;
}
if(!preg_match("/^[0-9]{1,60}$/",$_POST['del_long'])){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_del_long_error'])));
   exit;
}
if(!empty($_POST['adminpass2']) || !empty($_POST['adminpass3'])){
   if(CONFIG_ADMINPASSWORD != str_encrypt($_POST['adminpass1'])){
       header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_current_password_error'])));
       exit;
   }
   if(!preg_match("/^[0-9a-z_]{3,60}$/i",$_POST['adminpass2'])){
       header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_warning_new_password_error'])));
       exit;
   }
   $adminpass = str_encrypt($_POST['adminpass2']);
}else{
   $adminpass = CONFIG_ADMINPASSWORD;
}

$website       = str_encode($_POST['website']);
$weburl        = str_encode($_POST['weburl']);

$config = "<?php
//System Setting
define('CONFIG_ADMINUSERNAME', '".$_POST['adminuser']."');// Admin Username
define('CONFIG_ADMINPASSWORD', '".$adminpass."');// Admin Password
define('CONFIG_EMAIL',         '".$_POST['email']."');// Admin E-mail

define('CONFIG_WEBSITE',       '".$website."');// Website Name,only view
define('CONFIG_WEBURL',        '".$weburl."');// Website url,only view

define('CONFIG_URL',           '".$_POST['url']."');// The URL of where program install,terminative is /
define('CONFIG_LANGUAGE',      '".$_POST['language']."');// Default language
define('CONFIG_WEBINTRO_LONG', '".$_POST['webintro_long']."');// The user webinfo's long
define('CONFIG_LAST_VISITOR',  '".$_POST['last_visitor']."');// How many visitor's amply info to chalk up
define('CONFIG_IFCOUNT_LONG',  '".$_POST['ifcount_long']."');// The time long of prevent count[86400]
define('CONFIG_ONLINE_LONG',   '".$_POST['online_long']."');// The time long of online[600]
define('CONFIG_DEL_NUMBER',    '".$_POST['del_number']."');// How many is exceeded to delete of number
define('CONFIG_DEL_LONG',      '".$_POST['del_long']."');// How many is exceeded to delete of long,default is 10 day
define('CONFIG_IFUSER',        '".$_POST['ifuser']."');// Allow multiuser,y=yes,n=no
define('CONFIG_IFUSERLIST',    '".$_POST['ifuserlist']."');// Allow display users list,y=yes,n=no
define('CONFIG_IFVIEW',        '".$_POST['ifview']."');// Allow anonymous users view visit log,y=yes,n=no
?>
";

@chmod("config.php",0666);
if(write_file("config.php",$config)) {
      header("location:prompt.php?act=succeed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_succeed'])));
      exit;
}else{
      header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['admin_amend_failed'])));
      exit;
}

}

echo "<br></td></tr></table>";
include_once 'include/footer.php';
?>
